package jdbc;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 更新数据库里面的数据
        try(
                Connection conn = DBUtil.getConnection();
                ){
            System.out.println("请输入你想删除的用户的昵称");
            String nickName = scanner.nextLine();
            // 删除userinfo表里面的某条数据
            String sql = "DELETE FROM userinfo WHERE nickname = '" + nickName + "'";
            // 可以打印sql语句查看sql语句是否编写错误
            System.out.println(sql);

            // 创建statement对象去执行sql语句
            Statement statement = conn.createStatement();

            // 接收返回值
            int result = statement.executeUpdate(sql);
            if (result > 0){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
